import {BaseApi} from "@/api/base";
import request from "@/utils/request";
import {user} from "@/view/dashboard/user/user_api";
import {ref} from 'vue'
import {message} from "@/utils/message";
class Project_api extends BaseApi{
    base='/api/v1/project'
    CPro = []
    userlist = ref([])
    CPuserlist = ref([])
    drawerDia = ref(false)
    innerDrawer = ref(false)

    Adduser = async (users) =>{
        if (users.length === 0){
            message.error("未选择用户")
            return
        }
        await request({
            url: this.base + "/user",
            method: 'put',
            data:{
                "Users":users,
                "ID":this.CPro.id
            }
        }).then((response) => {
            this.Rmes(response)
        })
        await this.ListProUsers()
    }

    Deleteuser = async (users) =>{
        if (users.length === 0){
            message.error("未选择用户")
            return
        }
        await request({
            url: this.base + "/user",
            method: 'delete',
            data:{
                "Users":[users],
                "ID":this.CPro.id
            }
        }).then((response) => {
            this.Rmes(response)
        })
        await this.ListProUsers()
    }

    ListProUsers= async (row) =>{
        await request({
            url: this.base + "/users/"+this.CPro.id,
            method: 'get',
        }).then(async (response) => {
            this.CPuserlist.value = await response.data.data
        })
    }

    ListUser = async (row) =>{
        await user.List()
        this.CPro = row
        this.userlist.value = await user.data.value
        this.CPuserlist.value = await row.users
        this.drawerDia.value = true
        console.log(this.userlist.value)
    }

}

export const project = new Project_api()